/*
#    Copyright By Schips, All Rights Reserved
#    https://gitee.com/schips/
#
#    File Name:  dm_app__demo.c
#    Created  :  2020-08-12 09:47:33
*/

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <poll.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>


int main(int argc, char *argv[])
{
    /* ret获取返回值, fd获取文件句柄 */
    int ret, fd;

    char buff[5];

    /* 获取文件句柄, O_NONBLOCK表示非阻塞访问 */
    fd = open("/dev/dm", O_RDWR | O_NONBLOCK);
    //fd = open(filename, O_RDWR | O_NONBLOCK);
    if(fd < 0)
    {
        printf("can not open file %s\r\n", filename);
        return -1;
    }

    while(1)
    {
        ret = write(fd, "0", sizeof("0"));
        sleep(1);
        ret = write(fd, "1", sizeof("1"));
        sleep(1);
        read(fd, buff, sizeof(buff));
        printf("buff %s\n", buff);
        sleep(1);
    }

    close(fd);
    return ret;
}

